﻿/* Mouse Trailer */
/* Developed by Carlos Yanez */

package com.solidumgame.locroninja.juego
{
	import com.solidumgame.locroninja.juego.Partida;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;

	public class MouseTrailer extends Sprite
	{
		/* Light ball object */
		
		
		
		/* Constructor */

		public function MouseTrailer():void
		{
		
		}

		public static function empezarTrailer():void{
			//Mouse.hide();
			//Partida.stage.addEventListener(MouseEvent.MOUSE_MOVE, startTrailer);
		}
		
		public static function removerTrailer():void{
			Mouse.show();
			Partida.stage.removeEventListener(MouseEvent.MOUSE_MOVE, startTrailer);
		}
		
		private static function startTrailer(e:MouseEvent):void
		{
			var lightBall:LightBall;
			/* Create a new LightBall object */

			lightBall = new LightBall();

			/* Position */

			lightBall.x = e.localX;//+ Math.random() * lightBall.width;
			lightBall.y = e.localY ;//- Math.random() * lightBall.height;

			/* Add to Stage */

			Partida.stage.addChild(lightBall);

			/* Add Listener to Animate function */

			lightBall.addEventListener(Event.ENTER_FRAME, animate);
		}

		/* Animate function */

		private static function animate(e:Event):void
		{
			/* Alpha */

			e.target.alpha -= 0.05;

			/* If lightBall is no longer visible, remove it */

			if (e.target.alpha <= 0)
			{
				e.target.removeEventListener(Event.ENTER_FRAME, animate);

				Partida.stage.removeChild(e.target as Sprite);
			}

			/* Scale */

			e.target.scaleX -= 0.05;
			e.target.scaleY -= 0.05;

		
		}
	}
}